package com.bl.weilan.manager.controller.tradereport;


import com.bl.weilan.common.ApiResponseBody;
import com.bl.weilan.dao.model.TradeReportEntity;
import com.bl.weilan.service.biz.tradereport.TradeReportService;
import com.bl.weilan.service.vo.DelBody;
import com.bl.weilan.service.vo.DelListBody;
import com.bl.weilan.service.vo.tradereport.TradeReportAddVo;
import com.bl.weilan.service.vo.tradereport.TradeReportListVo;
import com.bl.weilan.service.vo.tradereport.TradeReportModVo;
import com.bl.weilan.service.vo.tradereport.TradeReportListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.BindingResult;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import com.bl.weilan.common.ApiResponseBody;
import com.bl.weilan.dao.model.InformationEntity;
import com.bl.weilan.dao.model.NewsEntity;
import com.bl.weilan.manager.controller.BaseController;
import com.bl.weilan.service.biz.information.InformationService;
import com.bl.weilan.service.vo.DelBody;
import com.bl.weilan.service.vo.DelListBody;
import com.bl.weilan.service.vo.information.InformationAddVo;
import com.bl.weilan.service.vo.information.InformationModVo;
import com.bl.weilan.service.vo.information.InformationListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@Log4j2
@RequestMapping(value = {"/weilan/manager/trade_report"})
@Api(value = "行业报告相关", description = "行业报告相关")
public class TradeReportController {

    @Autowired
    TradeReportService tradeReportService;

    @ApiOperation(value = "根据行业id获取行业报告列表", notes = "根据行业id获取行业报告列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_list"})
    public ApiResponseBody<TradeReportListVo> getlist(
            @RequestParam(value = "id", required = true) String id,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,
            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);

        TradeReportListVo tradeReportListVo = tradeReportService.getListManager(id, pageable);

        return ApiResponseBody.createSuccessBody(tradeReportListVo);
    }

    @ApiOperation(value = "发布行业报告", notes = "增加行业报告 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/add"})
    public ApiResponseBody add(
            @Valid @RequestBody TradeReportAddVo body, BindingResult result,
            HttpServletRequest request) {

//        ApiResponseBody validResult = validParams(result);
//        if (validResult != null) {
//            return validResult;
//        }

        tradeReportService.addTradeReport(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "查询单条行业报告详情", notes = "查询单条行业报告")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String")})
    @GetMapping(value = {"/get_detail"})
    public ApiResponseBody<TradeReportEntity> tradereportDetail(
            @RequestParam(value = "id", required = true) String id,
            HttpServletRequest request) {

        TradeReportEntity tradereportEntity = tradeReportService.getTradeReportById(id);

        return ApiResponseBody.createSuccessBody(tradereportEntity);
    }

    @ApiOperation(value = "删除批量", notes = "批量删除行业报告 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del_list"})
    public ApiResponseBody delList(
            @Valid @RequestBody DelListBody body, BindingResult result,
            HttpServletRequest request) {

        tradeReportService.delList(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "删除一个行业报告", notes = "删除单个行业报告信息 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del"})
    public ApiResponseBody del(
            @Valid @RequestBody DelBody body, BindingResult result,
            HttpServletRequest request) {


        tradeReportService.del(body);

        return ApiResponseBody.createSuccessBody(null);
    }


    @ApiOperation(value = "修改一条行业报告信息", notes = "修改行业报告信息 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/modify"})
    public ApiResponseBody modify(
            @Valid @RequestBody TradeReportModVo body, BindingResult result,
            HttpServletRequest request) {

//        ApiResponseBody validResult = validParams(result);
//        if (validResult != null) {
//            return validResult;
//        }

        tradeReportService.modify(body);

        return ApiResponseBody.createSuccessBody(null);
    }


}
